package com.supermarket.util;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class sqlsession {
    static SqlSessionFactory factory=null;
    static
    {
        InputStream inputStream= null;
        try {
            inputStream = Resources.getResourceAsStream ("Mapper.xml");
        } catch (IOException e) {
            e.printStackTrace ();
        }
        factory = new SqlSessionFactoryBuilder ().build ( inputStream );
    }
    public static SqlSession getsqlsession(){
        //False表示开启事务，不自动提交，关闭自动提交事务
        return factory.openSession (true);
    }

}
